package homework;

public class Teacher implements Comparable<Teacher>{
    private String name;
    private int age;

    //自定义比较规则
    @Override
    public int compareTo(Teacher o) {
        //this 与 o 比较
        //返回的数据： 负数 this小/ 0 相等/正数  this大
        if(this.age < o.age){
            return -1;
        }else if(this.age == o.age){
            return 0;
        }
        return 1;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    Teacher(String name,int age){
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


}
